<admintpl file="header" />
<link href="__TMPL__Public/assets/css/css-loader.css" rel="stylesheet" />
<link href="__TMPL__Public/assets/js/lobibox-master/dist/css/lobibox.min.css" rel="stylesheet" />
</head>
<body>
    <!-- Loader -->
    <div class="loader loader-default" data-text="页面加载中···"></div>
    <div class="wrap js-check-wrap">
        <ul class="nav nav-tabs">
            <li><a href="{:U('PaymentReview/index')}">工程款支付报审表管理</a></li>
            <if condition="I('request.isUpload/s','') eq '1'">
                <li><a href="{:U('PaymentReview/edit', array('id'=>I('request.id/s','')))}">新增工程款支付报审</a></li>
                <li class="active"><a href="#">工程量清单报审表</a></li>
                <else />
                <if condition="($Role eq 2) AND ($userrole['role'] eq 5)">
                    <li><a href="{:U('PaymentReview/add')}">新增工程款支付报审</a></li>
                </if>
                <li><a href="{:U('PaymentReview/view', array('id'=>I('request.id/s','')))}">查看工程款支付报审</a></li>
                <li class="active"><a href="{:U('PaymentReview/projectview', array('id'=>I('request.id/s','')))}">工程量清单报审表</a></li>
            </if>
        </ul>
        <form class="well form-search form-inline content" method="post" action="">
            <div class="form-group">
                <label></label>
                <select class="exceltype form-control" name="exceltype" id="exceltype">
                    <foreach name="excel" item="vo">
                        <option value="{$key}">{$vo}</option>
                    </foreach>
                </select>
                <if condition="I('request.isUpload/s','') eq '1'">
                    <input type="hidden" name="id" id="tableid" value="{:I('request.id/s','')}">
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="javascript:void(0);" class="btn upBtn btn-primary" name="attachment">选择文件</a>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="javascript:void(0);" class="btn impBtn btn-primary">导入</a>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="javascript:void(0);" class="btn pubBtn btn-danger" title="提交后数据不可修改">提交</a>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <a href="{:U('PaymentReview/edit', array('id'=>I('request.id/s','')))}" class="btn backBtn btn-warning">返回</a>
                    <input type="file" id="upFile" name="upFile" style="display:none" />
                </if>
            </div>
        </form>
        <div class="showContent">

        </div>
    </div>
    <script src="__PUBLIC__/js/common.js"></script>
    <script src="__TMPL__Public/assets/js/lobibox-master/dist/js/lobibox.min.js"></script>

    <script type="text/javascript">
        $(document).ready(function (e) {
            // 变更下拉的时候更改数据
            $(".exceltype").change(function () {
                getData();
            });

            // 获取数据
            getData = function () {
                var type = $(".exceltype").val(), reqUrl;
                if (type == 1 || type == 2) {
                    reqUrl = "{:U('PaymentReview/technicalview', array('id'=>I('request.id/s',''), 'isAudit' => I('request.isAudit/s',''), 'level' => I('request.level/s',''), 'deptId' => I('request.deptId/s','')))}&type=" + type;
                    //$(".pubBtn").show();
                } else if (type == 3) {
                    reqUrl = "{:U('PaymentReview/qpsview', array('id'=>I('request.id/s','')))}";
                    //$(".pubBtn").hide();
                } else if (type == 4) {
                    reqUrl = "{:U('PaymentReview/psview', array('id'=>I('request.id/s','')))}";
                    //$(".pubBtn").hide();
                } else if (type == 5) {
                    reqUrl = "{:U('PaymentReview/omlview', array('id'=>I('request.id/s',''), 'isAudit' => I('request.isAudit/s',''), 'level' => I('request.level/s',''), 'deptId' => I('request.deptId/s','')))}";
                    //$(".pubBtn").hide();
                } else if (type == 6) {
                    reqUrl = "{:U('PaymentReview/ppview', array('id'=>I('request.id/s',''), 'isAudit' => I('request.isAudit/s',''), 'level' => I('request.level/s',''), 'deptId' => I('request.deptId/s','')))}";
                    //$(".pubBtn").hide();
                } else {
                    requrl = '#'
                }
                $(".showContent").load(reqUrl);
            }

            // 初始化数据
            getData();

            window.obj = '';
            // 选择图片
            $(document).on("click", ".upBtn", function (e) {
                window.obj = $(this);
                $("#upFile").click();
            });
            // 文件选择器change事件
            $("#upFile").on("change", function () {
                uploadFiles();
            });
            uploadFiles = function () {
                if ($("#upFile").val() == "") {
                    alert("请选择待上传文件！");
                    return false;
                }
                var name = window.obj.attr("name");
                var obj = window.obj;
                var imageURL = obj.next().find("input[name='" + name + "_filePath']").val() != undefined
						? obj.next().find("input[name='" + name + "_filePath']").val()
						: "";

                $.ajaxFileUpload({
                    url: "{:U('PaymentReview/upload')}",
                    secureuri: false, //安全协议
                    fileElementId: 'upFile', //id
                    type: 'post',
                    dataType: 'json',
                    data: {
                        'imageURL': imageURL,
                        'folder': "payment_review",
                        'ajax': 1
                    },
                    async: false,
                    error: function (data, status, e) {
                        alert("服务器内部错误！");
                    },
                    success: function (json) {
                        if (json.rtnType == 'T') {
                            html = "<span class='controls' style='margin-left:10px;'>   \n"
								+ "	<input type='hidden' name='" + name + "' value='" + json.rtnResult + "' />    \n"
								+ "	<input type='hidden' name='" + name + "_name' value='" + json.file_name + "' />    \n"
								+ json.file_name
								+ "</span>";
                            $(".controls").remove();
                            obj.after(html);
                        } else {
                            alert(json.rtnMsg);

                        }
                    },
                    complete: function (xmlHttpRequest) {
                        $("#upFile").replaceWith('<input type="file" id="upFile" name="upFile" style="display:none" />');
                        $("#upFile").on("change", function () {
                            uploadFiles();
                        });
                    }
                });
            }

            // 点击导入
            $('.impBtn').click(function () {

                $.ajax({
                    type: "POST",
                    url: "{:U('PaymentReview/addPostFile')}",
                    data: $('form.content').serialize(),
                    beforeSend: function (XMLHttpRequest) {
                        var inobj = $("input[name='attachment']");
                        if (inobj.val() == undefined || inobj.val() == '') {

                            alert("请选择文件");
                            //Lobibox.alert("error",{msg: "请选择文件",title: '系统提示'});
                            return false;
                        }
                        else {
                            $(".loader").show();
                            $(".loader").addClass("is-active").attr("data-text", "正在处理，请稍等片刻~");
                        }
                    },
                    success: function (data) {
                        if (data.state == "fail") {
                            alert(data.info);
                        }
                        $(".upBtn").next("span").remove();
                        getData();
                        //加载完毕移除加载动画
                        $(".loader").removeClass("is-active");
                        $(".loader").hide();
                    },
                    error: function () { }
                });
            });

            // 点击提交
            $('.pubBtn').click(function () {

                $.ajax({
                    type: "POST",
                    url: "{:U('PaymentReview/publishs')}",
                    data: {
                        "exceltype": $("#exceltype").val(),
                        "sheet": $("select.sheetType").find("option:selected").text(),
                        "id": $("#tableid").val(),
                        "AJAX": 1
                    },
                    beforeSend: function (XMLHttpRequest) {
                        var type = $("#exceltype").val();
                        var length = $(".showContent tbody").find("td.bg-danger").length;
                        if (length > 0) {
                            alert("本期上报数据与累计上报数据之和不能超过清单量，请修正后再提交");
                            return false;
                        }

                    },
                    success: function (data) {

                        alert("提交成功!");
                    },
                    error: function () { }
                });
            });
        });
    </script>
</body>
</html>